//
//  LKTabbarViewController.m
//  Mideleague_Shop
//
//  Created by Zhiwang on 2020/5/22.
//  Copyright © 2020 Zhiwang. All rights reserved.
//

#import "LKTabbarViewController.h"
#import "LKHomeViewController.h"
#import "LKMineViewController.h"
#import "LKAllianceViewController.h"
#import "LKAggregatePaymentViewController.h"
@interface LKTabbarViewController ()

@end

@implementation LKTabbarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
//        [self createHomepageUI];
    // Do any additional setup after loading the view.
}
-(void)viewWillAppear:(BOOL)animated{
    UIView *view = [[UIView alloc] init];
    view.frame = self.tabBar.bounds;
    [[UITabBar appearance] insertSubview:view atIndex:0];
    //     改变标题字体颜色和大小
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor blackColor]} forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{ NSForegroundColorAttributeName : [UIColor clearColor]} forState:UIControlStateSelected];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Medium" size:13.0]}            forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName:[UIFont fontWithName:@"PingFangSC-Medium" size:13.0]}            forState:UIControlStateSelected];

    if (@available(iOS 13.0, *)) {
            // titColor就是选中的颜色
            self.tabBar.tintColor = yellowDefaultColor;
      //如果需要设置默认颜色可以使用setUnselectedItemTintColor来设置未选中颜色
//           [self.tabBar setUnselectedItemTintColor:UIColor redColor];
        } else {
            
        // 统一给所有的UITabBarItem设置文字属性
        UITabBarItem *item = [UITabBarItem appearance];
//        [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
//        [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
        }
    [self createHomepageUI];
}

-(void)createHomepageUI{
    LKHomeViewController *homePageVc = [[LKHomeViewController alloc] init];
    LKAggregatePaymentViewController *paymentvc = [[LKAggregatePaymentViewController alloc] init];
    LKAllianceViewController *allianceVc = [[LKAllianceViewController alloc] init];
    LKMineViewController *MineVc = [[LKMineViewController alloc] init];
    UINavigationController *homePageNav = [[UINavigationController alloc] initWithRootViewController:homePageVc];
    UINavigationController *paymentNav = [[UINavigationController alloc] initWithRootViewController:paymentvc];
    UINavigationController *allianceNav = [[UINavigationController alloc] initWithRootViewController:allianceVc];
    UINavigationController *MineNav = [[UINavigationController alloc] initWithRootViewController:MineVc];
//    homePageNav.tabBarItem.title = @"首页";
    MineNav.tabBarItem.title = @"我的";
    allianceNav.tabBarItem.title = @"联盟";
    paymentNav.tabBarItem.title = @"首页";
    [homePageNav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:yellowDefaultColor} forState:UIControlStateSelected];
    [MineNav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:yellowDefaultColor} forState:UIControlStateSelected];
    [allianceNav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:yellowDefaultColor} forState:UIControlStateSelected];
    [paymentNav.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:yellowDefaultColor} forState:UIControlStateSelected];
    //首页
    paymentNav.tabBarItem.image = [[UIImage imageNamed:@"tabbar_home"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    paymentNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_home_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //联盟
    allianceNav.tabBarItem.image = [[UIImage imageNamed:@"tabbar_lianmeng"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    allianceNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_lianmeng_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //我的
    MineNav.tabBarItem.image = [[UIImage imageNamed:@"tabbar_mine"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    MineNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"tabbar_mine_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    paymentNav.tabBarItem.imageInsets = UIEdgeInsetsMake(6, 0, -6, 0);

//    goVc.tabBarItem.image = [[UIImage imageNamed:@"after4"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    showNav.tabBarItem.image = [[UIImage imageNamed:@"after5"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    exploreNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"fore1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    centerPageNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"fore3"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    goNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"fore4"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//    showNav.tabBarItem.selectedImage = [[UIImage imageNamed:@"fore5"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    NSArray *array = [NSArray arrayWithObjects:paymentNav,MineNav, nil];
    self.viewControllers = array;
}
@end
